package com.winit.test;

import com.winit.base.BaseDelete;
import com.winit.base.BaseParam;
import com.winit.base.ParamType;
import com.winit.mycat.MycatConnUtil;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by wangjian on 17/7/3.
 */
public class Delete {

    static void DeleteA(Connection conn) {
        String a_sql = "DELETE FROM a WHERE column_4 = ?";
        List<BaseParam> list = new ArrayList<>();
        list.add(new BaseParam(1, ParamType.STRING, "打发的====5====aaaaaa"));
        BaseDelete.deleteT(conn, a_sql, list);
    }

    static void DeleteAAll(Connection conn) {
        String a_sql = "DELETE FROM a";
        BaseDelete.deleteT(conn, a_sql, new ArrayList<BaseParam>());
    }

    static void DeleteB(Connection conn) {
        String b_sql = "DELETE FROM b WHERE column_2 = ?";
        List<BaseParam> list = new ArrayList<>();
        list.add(new BaseParam(1, ParamType.INT, 12));
        BaseDelete.deleteT(conn, b_sql, list);
    }

    static void DeleteBAll(Connection conn) {
        String b_sql = "DELETE FROM b";
        List<BaseParam> list = new ArrayList<>();
        BaseDelete.deleteT(conn, b_sql, list);
    }

    static void DeleteC(Connection conn) {
        String c_sql = "DELETE FROM c WHERE column_12 = ?";
        List<BaseParam> list = new ArrayList<>();
        list.add(new BaseParam(1, ParamType.INT, 12));
        BaseDelete.deleteT(conn, c_sql, list);
    }

    static void DeleteCAll(Connection conn) {
        String c_sql = "DELETE FROM c ";
        List<BaseParam> list = new ArrayList<>();
        BaseDelete.deleteT(conn, c_sql, list);
    }

    static void DeleteD(Connection conn) {
        String d_sql = "DELETE FROM global_d WHERE column_22 = ?";
        List<BaseParam> list = new ArrayList<>();
        list.add(new BaseParam(1, ParamType.INT, 5));
        BaseDelete.deleteT(conn, d_sql, list);
    }

    static void DeleteDAll(Connection conn) {
        String d_sql = "DELETE FROM global_d ";
        List<BaseParam> list = new ArrayList<>();
        BaseDelete.deleteT(conn, d_sql, list);
    }

    public static void main(String[] args) throws Exception {
        Connection connection = null;
//       mycat
        connection = MycatConnUtil.getMycatConn();


        if (connection != null) {
            DeleteA(connection);
//            DeleteAAll(connection);

//            DeleteB(connection);
//            DeleteBAll(connection);

//            DeleteC(connection);
//            DeleteCAll(connection);

//            DeleteD(connection);
//            DeleteDAll(connection);

            connection.close();
        }
    }
}
